<template>
	<view class="header">
		<view class="logo">
			<image src="../../static/img/nav/logo.png"></image>
		</view>
		<view class="sewingLine">
			<view class="sewSelect" @click="sewShow=true">
				<!-- <image src="../../static/img/nav/updown.png"></image> -->
				<uni-icons v-if="!disabled" type="bottom" color="#fff" size="20"></uni-icons>
				<text>{{ $store.state.sewingName || sewingName }}</text>	
			</view>
			<u-picker v-if="!disabled" :show="sewShow" :columns="columnsSew" @cancel="sewShow = false" @confirm="confirmSewingLine" keyName="shiftTeam" :cancelText="$t('common.cancel')"
				:confirmText="$t('common.complete')"></u-picker>
		</view>
		<view class="userInfo">
			<view class="user item-info">
				<image src="../../static/img/nav/user.png"></image>
				<text>{{ userInfo.realName }}</text>
			</view>
			<view class="lang item-info">
				<image src="../../static/img/nav/lang.png"></image>
				<u-picker :show="show" :columns="columnsLang" @cancel="cancel" @confirm="confirm" keyName="text" :cancelText="$t('common.cancel')"
					:confirmText="$t('common.complete')"></u-picker>
				<view class="langtext" @click="show=true">
					<text>{{ value || language }}</text>
				</view>
			</view>
			<view class="logout item-info" @click="logout">
				<image src="../../static/img/nav/logout.png"></image>
				<text>{{$t('common.logoutLogin')}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import storage from "@/utils/storage.js"
	import { getSewingLine } from "@/api/nav.js"
	export default {
		data() {
			return {
				isAndroid: true,
				userInfo: storage.get('userInfo'),
				sewingName: storage.get('currentSewLineInfo') ? storage.get('currentSewLineInfo').sewingName : this.$t('placeholder.msg0'),
				startingUpRateList: {},
				value : '',
				columnsSew: [
					[]
				],
				columnsLang: [
					[
						{
							text: this.$t('locale.zh-hans'),
							code: 'zh-Hans'
						},
						{
							text: this.$t('locale.en'),
							code: 'en'
						},
					]
				],
				show: false,
				sewShow: false
			};
		},
		computed: {
			language() {
				return uni.getStorageSync('language') || this.$t('locale.zh-hans')
			}
		},
		props: {
			type:String,
			disabled:Boolean
			
		},
		mounted() {
			this.getsewingLineInfo()
		},
		methods: {
			// 获取缝制线信息
			getsewingLineInfo() {
				getSewingLine({ qc: this.userInfo.id }).then(res => {
					if (res.code !== 0) return uni.$u.toast(res.msg)
					res.data.map(item => {
						let sewingObj = {}
						sewingObj.shiftTeam = `${item.workShiftName}-${item.teamName}`
						sewingObj.sewingId = item.sewingId
						this.columnsSew[0].push(sewingObj)
					})
				})
			},
			// 选择语言
			// 选择语言
			onLocaleChange(e) {
				let systemInfo = uni.getSystemInfoSync();
				this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
				if (this.isAndroid) {
					this.$i18n.locale = e.code;
					uni.setStorageSync('lang', e.code)
					let getSystemInfo = this.$store.getters.getSystemInfo
					getSystemInfo.language = e.code
					// this.$initMoment()
					this.$store.commit('SET_SYSTEM_INFO', getSystemInfo)
					}
				},
				cancel(e) {
					this.show = false
				},
				// 确定语言选择框
				confirm(e) {
					this.value = e.value[0].text
					storage.set('language', e.value[0].text)
					this.show = false
					this.onLocaleChange(e.value[0])
				},
				// 确定缝制线选择
				confirmSewingLine(e) {
					// if (this.sewingName === e.value[0].shiftTeam) return false
					// this.sewingName = e.value[0].shiftTeam
					let sewInfo = {
						sewingId: e.value[0].sewingId,
						sewingName: e.value[0].shiftTeam
					}
					// storage.remove('currentSewLineInfo')
					storage.set('currentSewLineInfo', sewInfo)
					this.$store.commit('SET_SEWING', e.value[0].shiftTeam)
					this.$emit('selectSewlingLine', sewInfo.sewingId)
					this.sewShow = false
				},
				// 退出登录
				logout() {
					uni.navigateTo({
						url: '/pages/quality/toLogin'
					})
				}
			}
	}
</script>

<style lang="scss" scoped>
	@import 'index.scss';
</style>
